package com.zh.web.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;

/**
 * 状态枚举类
 */
@Getter
@ApiModel("状态枚举")
public enum Status {

    DISABLE((short) 0, "关闭"),
    ENABLE((short) 1, "启用"),
    REVIEWING((short) 2, "审核中"),
    RETURNED((short) 3, "已退回"),
    APPEALING((short) 4, "申诉中"),
    BANED((short) 5, "封禁");
    @EnumValue
    @JsonValue
    @ApiModelProperty(value = "状态码", example = "0 1 3")
    private final Short code;
    private final String desc;

    Status(Short code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // 根据状态码获取对应的枚举对象
    public static Status fromCode(int code) {
        for (Status status : Status.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid status code: " + code);
    }

    // 根据状态描述获取对应的枚举对象
    public static Status fromDesc(String description) {
        for (Status status : Status.values()) {
            if (status.getDesc().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid status description: " + description);
    }


}
